//
//  DeleteView.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/7.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "DeleteView.h"

@implementation DeleteView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
//        self.alpha = 0;
//        UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
//        bgView.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.75];
//        [self addSubview:bgView];
        self.alpha = 0;
        //背景
        UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - BOTTOM_HEIGHT)];
        bgView.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.75];
        [self addSubview:bgView];
        //白色背景
        UIView * whiteBGView = [[UIView alloc] init];
        whiteBGView.backgroundColor = [UIColor whiteColor];
        whiteBGView.layer.cornerRadius = 6;
        whiteBGView.layer.masksToBounds = YES;
        [self addSubview:whiteBGView];
        //标题
        UILabel * titleLab = [[UILabel alloc] init];
        titleLab.backgroundColor = [UIColor clearColor];
        titleLab.text = @"您确定要删除";
        titleLab.textColor = [UIColor blackColor];
        titleLab.font = DEF_FontSize_14;
        titleLab.textAlignment = NSTextAlignmentCenter;
        [whiteBGView addSubview:titleLab];
        //横分割线
        UIView * lineView = [[UIView alloc] init];
        lineView.backgroundColor = getColor(@"f7f7f7");
        [whiteBGView addSubview:lineView];
        //取消按钮
        UIButton * cancelBtn = [[UIButton alloc] init];
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        cancelBtn.titleLabel.font = DEF_FontSize_14;
        [cancelBtn setBackgroundColor:[UIColor clearColor]];
        [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [whiteBGView addSubview:cancelBtn];
        //确定按钮
        UIButton * sureBtn = [[UIButton alloc] init];
        [sureBtn setTitle:@"确定" forState:UIControlStateNormal];
        [sureBtn setTitleColor:getColor(@"6cdaba") forState:UIControlStateNormal];
        sureBtn.titleLabel.font = DEF_FontSize_14;
        [sureBtn addTarget:self action:@selector(sureBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [whiteBGView addSubview:sureBtn];
        //竖分割线
        UIView * borderView = [[UIView alloc] init];
        borderView.backgroundColor = getColor(@"f7f7f7");
        [whiteBGView addSubview:borderView];
        __weak typeof (self)weakSelf = self;
        [whiteBGView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.mas_left).mas_offset(29/WIDTH_6_SCALE);
            make.right.equalTo(weakSelf.mas_right).mas_offset(-29/WIDTH_6_SCALE);
            make.center.equalTo(weakSelf).centerOffset(CGPointMake(0, -100/WIDTH_6_SCALE));
            make.height.mas_offset(112/WIDTH_6_SCALE);
        }];
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_offset(66/WIDTH_6_SCALE);
            make.top.left.right.equalTo(whiteBGView);
        }];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(whiteBGView);
            make.height.mas_offset(1/WIDTH_6_SCALE);
            make.top.equalTo(titleLab.mas_bottom);
        }];
        [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.equalTo(whiteBGView);
            make.width.equalTo(whiteBGView.mas_width).multipliedBy(0.5);
            make.top.equalTo(lineView.mas_bottom);
        }];
        [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.bottom.equalTo(whiteBGView);
            make.width.top.equalTo(cancelBtn);
        }];
        [borderView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView.mas_bottom);
            make.bottom.equalTo(whiteBGView.mas_bottom);
            make.width.mas_offset(1/WIDTH_6_SCALE);
            make.centerX.equalTo(whiteBGView.mas_centerX);
        }];
    }return self;
}
#pragma mark - action
- (void)cancelBtnClick{
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 0 ;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (void)sureBtnClick{
    if (self.sureDeleteSection) {
        self.sureDeleteSection();
    }
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 0 ;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (void)show{
    [[UIApplication sharedApplication].delegate.window addSubview:self];
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 1;
    }];
}
@end
